package sk.stuba.fiit.foo07.genex.gui;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JCheckBox;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;

public class CheckBoxTreeCellRenderer extends DefaultTreeCellRenderer {
    /**
     * 
     */
    private static final long serialVersionUID = 8107334924911925818L;

    private Color b = new Color(255, 255, 240);
    private Color s = new Color(255, 255, 190);

    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value,
            boolean sel, boolean expanded, boolean leaf, int row,
            boolean hasFocus) {

        DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
        Object obj = node.getUserObject();
        JCheckBox ret = new JCheckBox(obj.toString());
        ret.setBackground(b);
        if (obj instanceof CheckBoxCategory) {
            ret.setSelected(((CheckBoxCategory) obj).isSelected());
            if (ret.isSelected())
                ret.setBackground(s);
        }

        return ret;
    }
}
